package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.extern.slf4j.Slf4j;

//使用配置类创建外部bean
@Configuration
@Slf4j
public class OssConfiguration {
    //通过配置类 注入AliOssUtil类
    //通过参数注入AliOssProperties
    @Bean
    @ConditionalOnMissingBean//不存在的时候创建，单例
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {
        AliOssUtil aliOssUtil = new AliOssUtil(aliOssProperties.getEndpoint(), aliOssProperties.getAccessKeyId(), aliOssProperties.getAccessKeySecret(), aliOssProperties.getBucketName());
        log.info("开始创建AliOssUtil对象：{}", aliOssUtil);
        return aliOssUtil;
    }
}
